using UnityEngine;
using QFramework;
using UnityEngine.SceneManagement;

namespace ProjectIndieFarm
{
    public partial class PausePanel : ViewController
    {
        public static BindableProperty<bool> IsOn { get; } = new(false);
        private void Start()
        {
            IsOn.RegisterWithInitValue(value =>
            {
                if (value) OpenPausePanel();
                else ClosePausePanel();
            }).UnRegisterWhenGameObjectDestroyed(gameObject);
            BtnHome.onClick.AddListener(BtnHome_OnClick);
            BtnContinue.onClick.AddListener(BtnContinue_OnClick);
            BtnSetting.onClick.AddListener(BtnSetting_OnClick);
        }

        private void OnDestroy()
        {
            BtnHome.onClick?.RemoveListener(BtnHome_OnClick);
            BtnContinue.onClick?.RemoveListener(BtnContinue_OnClick);
            BtnSetting.onClick?.RemoveListener(BtnSetting_OnClick);
        }
        #region On Off
        private void OpenPausePanel()
        {
            transform.Show();
            Time.timeScale = 0;
        }
        private void ClosePausePanel()
        {
            transform.Hide();
            Time.timeScale = 1;
        }
        #endregion

        #region btn onclick
        private void BtnHome_OnClick()
        {
            SceneManager.LoadScene("GameStart");
        }
        private void BtnContinue_OnClick()
        {
            IsOn.Value = false;
        }
        private void BtnSetting_OnClick()
        {

        }
        #endregion
    }
}
